package com.itheima.service.impl;

import com.itheima.service.UserService;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

//第二步，在实现类中写注解。
//定义bean，后面添加bean的id
@Component("userService")
//设定bean的作用域
@Scope("singleton")//可以直接写@Scope
public class UserServiceImpl implements UserService {
    public void save() {
        System.out.println("user service is running...");
    }

//    设定bean的生命周期
    @PostConstruct
    public void init() {
        System.out.println("user service's init...");
    }
//  设定bean的生命周期
    @PreDestroy
    public void destroy() {
        System.out.println("user service's destroy...");
    }
}
